﻿using ShadowCode.Injection.Base;
using System.CodeDom.Compiler;

namespace ShadowCode.Injection.Injections;
public abstract class InjectionUnitBase(TransformData data) : UnitBase(data)
{
    private string? groupKey;
    private INamedTypeSymbol? typeDeclaration;

    public virtual SyntaxNode? Node { get; set; }

    /// <summary>
    /// 分组用的key
    /// </summary>
    public string GroupKey => groupKey ??= CreateGroupKey();

    /// <summary>
    /// 构造函数所属类定义
    /// </summary>
    public INamedTypeSymbol Declaration => typeDeclaration ??= CreateTypeDeclaration();

    /// <summary>
    /// 构造函数的类定义
    /// </summary>
    protected abstract INamedTypeSymbol CreateTypeDeclaration();

    /// <summary>
    /// 分组用的key
    /// </summary>
    protected abstract string CreateGroupKey();

    internal abstract void ImplementBuild(InjectionAttribute attribute, 
        IndentedTextWriter writer, List<string> arguments);

    /// <summary>
    /// 是否允许简单代码注册
    /// <br/>标记函数并且只有一个构造函数
    /// </summary>
    internal abstract bool CanSimple { get; }
}